<template lang="pug">
  ModuleWrapper(title="蔬菜产量及产值" flex="1")
    .chart-wrap(ref="chart")
</template>

<script>
export default {
  name: "ModulePopulation",
  data() {
    return {
      chart: null,
      xAxisData: [2016, 2017, 2018, 2019, 2020 ]
    }
  },
  methods: {
    renderChart() {
      this.chart = this.$echarts.init(this.$refs['chart']);
      this.chart.setOption({
        tooltip: {
          trigger: 'axis'
        },
        legend: {
          data: ['产量', '种植面积'],
          textStyle: {
            color: '#FFF',
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          top: '15%',
          containLabel: true
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: this.xAxisData,
        },
        yAxis: [
          {
            type: 'value',
            name: '产量（万吨）',
            min: 0,
            max: 15,
            interval: 3,
            splitLine: {
              lineStyle: {
                color: ['rgba(255, 255, 255, .25)']
              }
            }
          },
          {
            type: 'value',
            name: '种植面积（万亩)',
            min: 0,
            max: 10,
            interval: 2,
            splitLine: {
              lineStyle: {
                color: ['rgba(255, 255, 255, .25)']
              }
            }
          }
        ],
        series: [
          {
            name: '产量',
            type: 'line',
            data: [13, 13, 13, 13, 11]
          },
          {
            name: '种植面积',
            type: 'line',
            yAxisIndex: 1,
            data: [6.5, 6.5, 6.5, 6.8, 6.3]
          },
        ]
      });
    },
  },
  mounted() {
    this.$nextTick(() => {
      this.renderChart();
    });
  }
}
</script>

<style lang="scss" scoped>
.module{
  display: flex;
  flex-direction: column;
  .chart-wrap{
    flex: 1;
  }
}
</style>
